<@t.header>
<link rel="stylesheet" href="${request.contextPath}/app/contract/css/contract-view.css">
</@t.header> <@t.body> <#if invalid?? && invalid>
<div class="row">
	<div class="col-md-12">
		<div class="alert alert-danger" role="alert">
			<strong>错误！</strong> 无效的合同信息或者系统异常！
		</div>
	</div>
</div>
<#elseif invalidType?? && invalidType>
<div class="row">
	<div class="col-md-12">
		<div class="alert alert-danger" role="alert">
			<strong>错误！</strong> 合同类型无效，请联系管理员！
		</div>
	</div>
</div>
<#else>
<div class="navbar navbar-default navbar-fixed-top padding-0 margin-0">
	<div class="container-fluid">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#suredy-form-navbar">
				<span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span>
			</button>
			<span class="navbar-brand"> <i class="icon-paste icon-large"></i> 编辑${data.type.value}
			</span>
		</div>
		<div class="collapse navbar-collapse" id="suredy-form-navbar">
			<ul class="nav navbar-nav suredy-form-bar">
				<li>
					<a href="javascript:void(0);" class="submit-contract-info">
						<i class="icon-ok icon-large"></i>
						保存
					</a>
				</li>
				<li>
					<a href="javascript:void(0);" class="reset-form-info">
						<i class="icon-undo icon-large"></i>
						重置表单
					</a>
				</li>
				<li>
					<a href="javascript:void(0);" class="back-view" data-id="${data.id}">
						<i class="icon-remove icon-large"></i>
						取消编辑
					</a>
				</li>
			</ul>
		</div>
	</div>
</div>

<div class="container" style="padding-top: 60px;">
	<form class="form-for-edit-sub" action="${request.contextPath}/sub-contract/edit-sub" method="post">
		<input type="hidden" name="id" value="${data.id}">

		<fieldset>
			<legend class="text-primary">基本信息</legend>
			<div class="row">
				<div class="col-md-12">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 分包名称
								</div>
							</div>
							<input type="text" class="form-control not-empty" name="name" value="${data.name}" placeholder="最多100个汉字">
						</div>
					</div>
				</div>
				<div class="col-md-12">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 分包编号
								</div>
							</div>
							<input type="text" class="form-control not-empty" name="no" value="${data.no}" placeholder="最多50个字符">
						</div>
					</div>
				</div>
				<div class="col-md-6">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 分包金额
								</div>
							</div>
							<input type="text" class="form-control not-empty number" name="price" value="${data.price}" placeholder="只能是数字">
							<div class="input-group-addon">元</div>
						</div>
					</div>
				</div>
				<div class="col-md-6">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 签订日期
								</div>
							</div>
							<input type="text" class="form-control not-empty datetimepicker" name="signDate" data-foot="false" data-format="yyyy-MM-dd" value="${(data.signDate?string('yyyy-MM-dd'))!''}" readonly="readonly">
						</div>
					</div>
				</div>
				<div class="col-md-6">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 分包单位
								</div>
							</div>
							<input type="text" class="form-control not-empty" name="companyB" value="${data.companyB}" placeholder="最多60个汉字">
						</div>
					</div>
				</div>
				<div class="col-md-6">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 建设单位
								</div>
							</div>
							<input type="text" class="form-control not-empty" name="companyA" value="${data.companyA}" readonly="readonly">
						</div>
					</div>
				</div>
				<div class="col-md-6">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 开工日期
								</div>
							</div>
							<input type="text" class="form-control not-empty datetimepicker" name="contractStart" data-foot="false" data-format="yyyy-MM-dd" value="${(data.contractStart?string('yyyy-MM-dd'))!''}" readonly="readonly" placeholder="请填写合同文件中的开始日期">
						</div>
					</div>
				</div>
				<div class="col-md-6">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 竣工日期
								</div>
							</div>
							<input type="text" class="form-control not-empty datetimepicker" name="contractEnd" data-foot="false" data-format="yyyy-MM-dd" value="${(data.contractEnd?string('yyyy-MM-dd'))!''}" readonly="readonly" placeholder="请填写合同文件中的结束日期">
						</div>
					</div>
				</div>
				<div class="col-md-12">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 结算方式
								</div>
							</div>
							<textarea rows="3" class="form-control not-empty" name="jiesuanWay" placeholder="最多500个汉字">${data.jiesuanWay}</textarea>
						</div>
					</div>
				</div>
				<div class="col-md-12">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 付款方式
								</div>
							</div>
							<textarea rows="3" class="form-control not-empty" name="fukuanWay" placeholder="最多500个汉字">${data.fukuanWay}</textarea>
						</div>
					</div>
				</div>
				<div class="col-md-12">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">
									<span class="not-null-star">*</span> 主要内容
								</div>
							</div>
							<textarea rows="3" class="form-control not-empty" name="mainContent" placeholder="最多1000个汉字">${data.mainContent}</textarea>
						</div>
					</div>
				</div>
				<div class="col-md-12">
					<div class="form-group">
						<div class="input-group">
							<div class="input-group-addon">
								<div class="form-item-title">备注</div>
							</div>
							<textarea rows="3" class="form-control" name="remark" placeholder="最多1000个汉字">${data.remark}</textarea>
						</div>
					</div>
				</div>
			</div>
		</fieldset>
	</form>
</div>
</#if> </@t.body> <@t.foot>

<script type="text/javascript">
	require([ ctxp + '/app/js/form-checker.js', 'jqueryForm', 'suredyDatetimepicker', '${request.contextPath}/app/contract/js/contract-view.js' ], function(formChecker) {
		$('.submit-contract-info').on('click', function() {
			var form = $('form.form-for-edit-sub');

			// 校验表单
			if (!formChecker(form)) {
				return false;
			}

			var $this = $(this);

			if ($this.hasClass('disabled'))
				return false;

			$this.addClass('disabled');

			form.ajaxSubmit({
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						var msg = (data && data.msg) || '修改合同失败！';
						alert(msg);
						$this.removeClass('disabled');
						return false;
					}

					window.location.href = Suredy.contextPath + '/sub-contract/view/${data.id}';
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('修改包合同失败！\n' + errorThrown);
					$this.removeClass('disabled');
					return false;
				}
			});
		});

		// 重置表单
		$('a.reset-form-info').on('click', function() {
			var form = $('form.form-for-edit-sub');

			if (form.length > 0) {
				form[0].reset();
			}
		});

		// 取消编辑
		$('a.back-view').on('click', function() {
			var $this = $(this);
			var id = $this.data('id');

			window.location.href = Suredy.contextPath + '/sub-contract/view/' + id;
		});
	});
</script>
</@t.foot>
